package com.xs.ai.entity;

import com.xs.ai.dto.EmailAttachment;
import com.xs.ai.dto.SuggestedAction;
import com.xs.ai.enums.EmailPriority;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.hibernate.annotations.Type;
import com.vladmihalcea.hibernate.type.json.JsonType;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Data
@Entity
@Table(name = "emails")
public class Email {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    private Long accountId;
    
    @Column(unique = true, nullable = false)
    private String messageId;
    private String threadId;
    
    @Column(columnDefinition = "TEXT")
    private String subject;
    
    private String senderEmail;
    private String senderName;
    
    @Type(JsonType.class)
    @Column(columnDefinition = "jsonb")
    private List<String> recipients;
    
    @Type(JsonType.class)
    @Column(columnDefinition = "jsonb")
    private List<String> cc;
    
    @Column(columnDefinition = "TEXT")
    private String bodyText;
    
    @Column(columnDefinition = "TEXT")
    private String bodyHtml;
    
    @Type(JsonType.class)
    @Column(columnDefinition = "jsonb")
    private List<EmailAttachment> attachments;
    
    private LocalDateTime receivedAt;
    private Boolean isRead = false;
    private Boolean isStarred = false;
    private String folder;
    
    // AI分析字段
    @Enumerated(EnumType.STRING)
    private EmailPriority aiPriority;
    
    private String aiCategory;
    private String aiSentiment;
    
    @Column(columnDefinition = "TEXT")
    private String aiSummary;
    
    @Type(JsonType.class)
    @Column(columnDefinition = "jsonb")
    private List<String> aiKeyPoints;
    
    @Type(JsonType.class)
    @Column(columnDefinition = "jsonb")
    private List<SuggestedAction> aiSuggestedActions;
    
    private Double aiImportanceScore;
    private LocalDateTime aiAnalyzedAt;
    
    // 用户操作
    @Enumerated(EnumType.STRING)
    private EmailPriority userPriority;
    private String userCategory;
    private LocalDateTime userArchivedAt;
    
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}